package com.lu.pojo.oop.instance;

import java.util.ArrayList;
import java.util.List;

/**
 * @author luzhenfang
 * @date 2020 04 26
 * @description instance]of 关键字的使用
 */
public class TestInstance {
    public static void method1(Person e) {
        e.getInfo();
        if (e instanceof Graduate) {
            System.out.println("a graduated student \na student");
        } else if (e instanceof Student) {
            System.out.println("a student");
        }
        System.out.println("a person");
        System.out.println("------------------------");
    }
    public static void main(String[] args) {
        Person person = new Person();
        Person student = new Student();
        Person graduate = new Graduate();
        List<Person> list = new ArrayList<>();
        list.add(person);
        list.add(student);
        list.add(graduate);

        for (Person p : list) {
            method1(p);
        }
    }
}
